package edu.pku.sei.transformation.editor.views.colors;

import java.util.HashMap;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.swt.graphics.Color;

public class ColorProvider {
	static private HashMap<String, Color> colorTable = new HashMap<String, Color>();
	static {
		colorTable.put(ColorConstants.black.toString(), ColorConstants.black);
		colorTable.put(ColorConstants.white.toString(), ColorConstants.white);
		colorTable.put(ColorConstants.red.toString(), ColorConstants.red);
		colorTable.put(ColorConstants.blue.toString(), ColorConstants.blue);
		colorTable.put(ColorConstants.green.toString(), ColorConstants.green);
	}

	static public Color getColor(int r, int g, int b) {
		Color c = null;
		if (r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255) {
			String k = "Color {" + r + ", " + g + ", " + b + "}";
			c = colorTable.get(k);
			if (c == null) {
				c = new Color(null, r, g, b);
				colorTable.put(k, c);
			}

		} else {
			c = getColor(0, 0, 0);
		}
		return c;
	}
}
